<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require dirname(__FILE__).'/pc_controller.php';

require_once dirname(__FILE__).'/menu.php';

class Bjmarathon_apply extends PC_controller {

    public function __construct(){
        parent::__construct();
        $this->load->model('Bjmarathoncustomermodel','m_customer');
    }

    public function index(){
        $data = parent::index();

        $this->load->view('admin/bjmarathon_apply',$data);
    }

    public function getApplyList() {
        $assist['where'] = getFilter($this->input->post(),Bjmarathoncustomermodel::$applySearchField);
        $assist['like'] = getFilter($this->input->post(),Bjmarathoncustomermodel::$applyLikeField);
        $assist['pagination'] = getPagination($this->input->post());


        $assist['select'] = '
            bjmarathon_customer.customer_id,
            bjmarathon_customer.bluemember_user_id,
            bjmarathon_customer.bluemember_phone,
            bjmarathon_apply.*
        ';
        list($list,$count) = $this->m_customer->getApplyListSection($assist);

        $this->response->setSuccess();
        $this->response->setItems($list);
        $this->response->setTotalCount($count);
        $this->response->responseExit();
    }

    public function exportApplyList() {
        @set_time_limit(0);
        @ini_set('memory_limit', '2048M');


        $assist['where'] = getFilter($this->input->get(),Bjmarathoncustomermodel::$applySearchField);
        $assist['like'] = getFilter($this->input->get(),Bjmarathoncustomermodel::$applyLikeField);

        $assist['select'] = '
            bjmarathon_customer.customer_id,
            bjmarathon_customer.bluemember_user_id,
            bjmarathon_customer.bluemember_phone,
            bjmarathon_apply.*
        ';
        list($list,$count) = $this->m_customer->getApplyListSection($assist);

        $this->load->library('excel');
        $this->excel->init('北京马拉松申请报名用户_'.date('YmdH').'.xls');
        $this->excel->addSheet('北京马拉松申请报名用户');
        $this->excel->addTitle(array(
            array('content'=>'顾客ID'),
            array('content'=>'bluemember用户ID'),
            array('content'=>'bluemember手机号'),
            array('content'=>'姓名'),
            array('content'=>'性别'),
            array('content'=>'血型'),
            array('content'=>'国籍'),
            array('content'=>'证件类型'),
            array('content'=>'证件号'),
            array('content'=>'出生日期'),
            array('content'=>'手机号1'),
            array('content'=>'手机号2'),
            array('content'=>'电子邮箱1'),
            array('content'=>'电子邮箱2'),
            array('content'=>'省份'),
            array('content'=>'城市'),
            array('content'=>'地区'),
            array('content'=>'通信地址'),
            array('content'=>'邮编'),
            array('content'=>'紧急联系人'),
            array('content'=>'紧急联系人电话'),
            array('content'=>'职业'),
            array('content'=>'年收入'),
            array('content'=>'教育程度'),
            array('content'=>'既往病史'),
            array('content'=>'选手类型'),
            array('content'=>'参加过的赛事'),
            array('content'=>'完赛成绩'),
            array('content'=>'一年内是否参加过马拉松'),
            array('content'=>'一年内最好成绩的赛事'),
            array('content'=>'一年内最好成绩'),
            array('content'=>'公益组织第一选项'),
            array('content'=>'公益组织第二选项'),
            array('content'=>'来源'),
            array('content'=>'创建时间'),
        ));

        $sex_array = array(
            1 => '男',
            2 => '女',
        );
        foreach ($list as $key => $value) {
            $gift_info = array();

            $this->excel->addRow(array(
                array('content' => $value['customer_id']),
                array('content' => $value['bluemember_user_id']),
                array('content' => $value['bluemember_phone']),
                array('content' => $value['apply_name']),
                array('content' => id2name($value['apply_sex'],$sex_array)),
                array('content' => $value['apply_blood']),
                array('content' => $value['apply_nationality']),
                array('content' => $value['apply_id_type'] == 1 ? '身份证': ''),
                array('content' => $value['apply_id_number']),
                array('content' => $value['apply_birthday']),
                array('content' => $value['apply_phone_1']),
                array('content' => $value['apply_phone_2']),
                array('content' => $value['apply_email_1']),
                array('content' => $value['apply_email_2']),
                array('content' => $value['apply_province']),
                array('content' => $value['apply_city']),
                array('content' => $value['apply_district']),
                array('content' => $value['apply_address']),
                array('content' => $value['apply_zipcode']),
                array('content' => $value['apply_emergency_contact_name']),
                array('content' => $value['apply_emergency_contact_phone']),
                array('content' => $value['apply_job']),
                array('content' => $value['apply_income']),
                array('content' => $value['apply_education']),
                array('content' => $value['apply_past_medical_history']),
                array('content' => $value['apply_player_type']),
                array('content' => $value['apply_join_game_name']),
                array('content' => $value['apply_join_game_score']),
                array('content' => $value['apply_join_last_year'] == 1 ? '是' : '否'),
                array('content' => $value['apply_join_last_year_name']),
                array('content' => $value['apply_join_last_year_score']),
                array('content' => $value['apply_mmunity_organization_1']),
                array('content' => $value['apply_mmunity_organization_2']),
                array('content' => $value['source']),
                array('content' => $value['apply_time_create']),
            ));
        }

        $this->excel->freezePanes(1,0);
        $this->excel->generate();
    }

}
/* End of file aa_game_history.php */
/* Location: ./application/controllers/aa_game_history.php */
